<%@ page import="java.net.URLEncoder" %>
<%@ page import="com.bestv.search.engine.connection.impl.HttpClientConnection" %>
<%@ page import="com.bestv.search.engine.connection.IConnection" %>
<%@ page import="java.io.InputStream" %>
<%@ page import="java.io.BufferedReader" %>
<%@ page import="java.io.InputStreamReader" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
</head>
<body>
<%
    String keyword = request.getParameter("k");
    if (keyword == null || "".equals(keyword)) keyword = "ldh";


    /*String req = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
            "<request>" +
            "<cmd>searchCategory</cmd>" +
            //"<category>type</category>" +
            "<start>0</start>" +
            "<limit>30</limit>" +
            "<keywords><![CDATA[新妓生传]]></keywords>" +
            "<filter><field>bizType</field><value>电影 电视剧 少儿</value><type>or</type></filter>" +
            //"<filter><field>domain</field><value>biz_hq_10017290</value></filter>" +
            "<filter><field>region</field><value>大陆</value></filter>" +
            "<filter><field>hd</field><value>0</value></filter>" +
            "</request>";*/
    String req = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
            "<request>" +
            "<cmd>suggest</cmd>" +
            "<limit>6</limit>" +
            "<keyword><![CDATA[q]]></keyword>" +
            "<userId>99999100</userId>" +
            "</request>";
    /*String req = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
            "<request>" +
            "<cmd>topn</cmd>" +
            "<limit>6</limit>" +
            "</request>";*/
    /*String req = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
            "<request>" +
            "<cmd>hit</cmd>" +
            "<mediacode>Umai:SERI/530741@BESTV.SMG.SMG</mediacode>" +
            "<keyword>qsmx</keyword>" +
            "<userId>99991000</userId>" +
            "</request>";*/
    /*String req = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
            "<request>" +
            "<cmd>history</cmd>" +
            "<limit>3</limit>" +
            "<userId>99991000</userId>" +
            "</request>";*/
    req = URLEncoder.encode(req, "UTF-8");

    IConnection connection = new HttpClientConnection();
    try {
        connection.connect("http://localhost:8080/engine/dosuggest?q=" + req);
        InputStream is = connection.request(new byte[0]);
        BufferedReader br = new BufferedReader(new InputStreamReader(is));
        StringBuffer sb = new StringBuffer();
        String line;
        while ((line = br.readLine()) != null) {
            sb.append(line);
        }
        out.println(sb.toString());
    } catch (Exception e) {
        System.out.println(e);
    } finally {
        connection.release();
    }
%>
</body>
</html>